package com.sskj.quantization.presenter;

import com.lzy.okgo.model.Response;
import com.lzy.okrx2.adapter.FlowableBody;
import com.sskj.common.base.HttpData;
import com.sskj.common.util.ToastUtil;
import com.sskj.lib.bean.PageBean;
import com.sskj.lib.http.JsonCallBack;
import com.sskj.lib.http.JsonConverter;
import com.sskj.quantization.bean.ProfitAllBean;
import com.sskj.quantization.bean.ProfitBean;
import com.sskj.quantization.http.HttpConfig;
import com.sskj.quantization.ui.activity.ProfitActivity;

import java.util.List;

import io.reactivex.Flowable;


public class ProfitActivityPresenter extends BasePresenter<ProfitActivity> {


    /**
     * 我的收益
     *
     * @param p    页码，默认1
     * @param size 页条数，默认5
     * @return
     */
    public Flowable<List<ProfitBean>> getProfitList(String p, String size) {
        return httpService.getProfitList(p, size)
                .converter(new JsonConverter<HttpData<PageBean<ProfitBean>>>() {
                })
                .adapt(new FlowableBody<>())
                .map(pageBeanHttpData -> pageBeanHttpData.getData().getList());
    }

    /**
     * 我的收益
     *
     * @return
     */
    public void getProfit() {
        httpService.getProfit()
                .execute(new JsonCallBack<HttpData<ProfitAllBean>>() {
                    @Override
                    public void onSuccess(Response<HttpData<ProfitAllBean>> response) {
                        HttpData<ProfitAllBean> httpData = response.body();
                        if (httpData.getStatus() == HttpConfig.OK) {
                            mView.updateUI(httpData.getData());
                        }
                    }
                });
    }
}
